/* Copyright (c) [2019年5月1日] [吴超]
[MBT_Studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
 */


#include "stdafx.h"
#include "../通用插座.h"
#include "list物理物体插座.h"


#include "list物体插座.h"
#include "list矢量插座.h"


#include <场景/场景.h>
#include <物理/物理.h>
#include <ppl.h>



using namespace std;


static std::vector<S_物理体*> g_物理体回收站;



C_物理材质_1D插座::C_物理材质_1D插座(u16string name) :C_插座基类(name, E_值类型::e_插座Type_物理材质_Array1D) {
	auto scene = f_scene_get场景(0);
	m_转换值 = (S_PhyMaterialArray*)f_core_array_new(0, sizeof(S_物理材质*));
	m_默认值 = (S_PhyMaterialArray*)f_core_array_new(0, sizeof(S_物理材质*));
	m_Value = m_默认值;
}

void* C_物理材质_1D插座::f_getData(uint8 链接ID) {
	C_插座基类* socket = f_getLinkOutSocket(链接ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_插座Type_物理材质_Array1D) {
			return socket->f_getData(0);
		}
		else {
			
		}

		m_Value = m_转换值;
	}
	else if (!m_映射指针) {
		m_Value = m_默认值;
	}
	return m_Value;
}

void C_物理材质_1D插座::f_setData(void* data, uint8 线程ID) {
	C_插座基类::f_setData(data, 线程ID);

	if (data) {
		m_Value = (S_PhyMaterialArray*)data;
		m_映射指针 = true;
	}
	else {
		m_Value = m_默认值;
		m_映射指针 = false;
	}
}






C_物理几何插座_1D::C_物理几何插座_1D(u16string name) :C_插座基类(name, E_值类型::e_插座Type_物理几何_Array1D) {
	m_转换值 = (S_PhyGeomArray*)f_core_array_new(0, sizeof(S_PhyGeomArray*));
	m_默认值 = (S_PhyGeomArray*)f_core_array_new(0, sizeof(S_PhyGeomArray*));
	m_Value = m_默认值;
}
C_物理几何插座_1D::~C_物理几何插座_1D() {
	f_core_array_free((S_Array*)m_转换值);
	f_core_array_free((S_Array*)m_默认值);
}

void* C_物理几何插座_1D::f_getData(uint8 链接ID) {
	C_插座基类* socket = f_getLinkOutSocket(链接ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_插座Type_物理几何_Array1D) {
			return socket->f_getData(0);
		}
		else {
			
		}
		m_Value = m_转换值;
	}
	else if (!m_映射指针) {
		m_Value = m_默认值;
	}
	return m_Value;
}

void C_物理几何插座_1D::f_setData(void* data, uint8 线程ID) {
	C_插座基类::f_setData(data, 线程ID);

	if (data) {
		m_Value = (S_PhyGeomArray*)data;
		m_映射指针 = true;
	}
	else {
		m_Value = m_默认值;
		m_映射指针 = false;
	}
}

bool C_物理几何插座_1D::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
		case E_值类型::e_插座Type_物理几何_Array1D:
		case E_值类型::e_插座Type_物理几何:
			return true;
	}
	return false;
}






C_插座_物理体_1D::C_插座_物理体_1D(u16string name) :C_插座基类(name, E_值类型::e_插座Type_物理体_Array1D) {
	m_转换值 = (S_PhyBodyArray*)f_core_array_new(0, sizeof(S_PhyBodyArray*));
	m_默认值 = (S_PhyBodyArray*)f_core_array_new(0, sizeof(S_PhyBodyArray*));
	m_Value = m_默认值;
}

C_插座_物理体_1D::~C_插座_物理体_1D() {
	f_core_array_free((S_Array*)m_转换值);
	f_core_array_free((S_Array*)m_默认值);
}

void* C_插座_物理体_1D::f_getData(uint8 当前插座连接线ID) {
	C_插座基类* socket = f_getLinkOutSocket(当前插座连接线ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_插座Type_物理体_Array1D) {
			return dynamic_cast<C_插座_物理体_1D*>(socket)->f_getData(0);
		}
		else if (socket->m_Type == E_值类型::e_插座Type_引用数据) {
		}
		else if (socket->m_Type == E_值类型::e_插座Type_引用数据) {
			auto& data = *DEF_引用插座数据(socket, 0);
			if (data.m_Type == E_值类型::e_Type_Object) {
				
			}
		}
		else if (socket->m_Type == E_值类型::e_Type_Object) {
			auto* data = DEF_物体插座数据(socket, 0);
			//m_Value.resize(1);
			//if(m_Value[0] == nullptr) m_Value[0] = new S_物理体();
			//m_Value[0]->m_绑定物体 = data;
		}
	}
	else if (!m_映射指针) {
		m_Value = m_默认值;
	}
	return m_Value;
}

void C_插座_物理体_1D::f_setData(void* data, uint8 线程ID) {
	C_插座基类::f_setData(data, 线程ID);

	if (data) {
		m_Value = (S_PhyBodyArray*)data;
	}
	else {
		m_Value = m_默认值;
	}
}

bool C_插座_物理体_1D::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
		case E_值类型::e_插座Type_物理体_Array1D:
		case E_值类型::e_插座Type_物理体:
			return true;
	}
	return false;
}

void C_插座_物理体_1D::f_释放数据() {
	
}






C_车轮属性插座Array1D::C_车轮属性插座Array1D(u16string name) :C_插座基类(name, E_值类型::e_插座Type_车轮_Array1D) {

}

C_车轮属性插座Array1D::~C_车轮属性插座Array1D() {
}

void* C_车轮属性插座Array1D::f_getData() {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		if (socket->m_Type == E_值类型::e_插座Type_车轮_Array1D) {
			return DEF_车轮属性Array1D插座Value(socket, 0);
		}
	}
	return &m_Value;
}

void C_车轮属性插座Array1D::f_setData(void * data, int64 ID) {
	m_Value = *(vector<S_车轮参数>*)data;
}







C_插座车辆属性_1D::C_插座车辆属性_1D(u16string name) :C_插座基类(name, E_值类型::e_插座Type_车辆_Array1D) {
	//m_车体属性.type = E_值类型::e_插座Type_车辆_Array1D;
	m_Value.resize(1);
}

C_插座车辆属性_1D::~C_插座车辆属性_1D() {
}

void C_插座车辆属性_1D::f_update(C_插座基类 * 连接到的输入节点, C_节点基类 * node) {
}

void * C_插座车辆属性_1D::f_getData() {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		if (socket->m_Type == E_值类型::e_插座Type_车辆_Array1D) {
			return dynamic_cast<C_插座车辆属性_1D*>(socket)->f_getData();
		}
		else if (socket->m_Type == E_值类型::e_Type_车辆) {
			//S_车体属性 data = DEF_车辆属性插座Value(socket, 0);
			//m_Value[0] = data;
		}
	}

	return &m_Value;
}

void C_插座车辆属性_1D::f_setData(void* data, int64 ID)
{
	C_插座基类::f_setData(data);

	m_Value = *((vector<S_车体属性>*)data);
	
}










